package com.hz.web.service.impl;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.annotation.Resource;

import org.springframework.stereotype.Service;

import com.hz.web.dao.DepartmentDao;
import com.hz.web.entity.DepartmentEntity;
import com.hz.web.service.IdepartmentService;
@Service
public class DepartmentImpl implements IdepartmentService {

	@Resource
	private DepartmentDao departmentDao;
	
	/**
	 * 添加部门信息
	 * @param parmsMap
	 * @return
	 */
	@Override
	public int adddDepartment(DepartmentEntity entity) {
		
		return departmentDao.adddDepartment(entity);
	}

	/**
	 * 查询部门信息
	 * @param parmsMap
	 * @return
	 */
	@Override
	public List<DepartmentEntity> queryDepartment(DepartmentEntity entity,int page ,int rows) {
		Map<String, Object> parmsMap = new HashMap<String, Object>();
		if(entity!=null){
			parmsMap.put("departmentCode", entity.getDepartmentCode());
			parmsMap.put("departmentName", entity.getDepartmentName());
			parmsMap.put("type", entity.getType());
			parmsMap.put("isDel", entity.getIsDel());
		}
		if(page!=0 && rows!=0){
			int index = (page-1)*rows;
			int end =rows; 
			parmsMap.put("index", index);
			parmsMap.put("end", end);
		}
		List<DepartmentEntity> ls = departmentDao.queryDepartment(parmsMap);
		if(ls==null){
			ls = new ArrayList<DepartmentEntity>();
		}
		return  ls;
	}

	/**
	 * 查询部门信息总条数
	 * @param parmsMap
	 * @return
	 */
	@Override
	public int queryDepartmentCount(DepartmentEntity entity) {
		Map<String, Object> parmsMap = new HashMap<String, Object>();
		if(entity!=null){
			parmsMap.put("departmentCode", entity.getDepartmentCode());
			parmsMap.put("departmentName", entity.getDepartmentName());
			parmsMap.put("type", entity.getType());
			parmsMap.put("isDel", entity.getIsDel());
		}
		return departmentDao.queryDepartmentCount(parmsMap);
	}

	/**
	 * 修改信息
	 * @param parmsMap
	 * @return
	 */
	@Override
	public int updateDepartment(DepartmentEntity entity) {
		Map<String, Object> parmsMap = new HashMap<String, Object>();
		if(entity!=null){
			parmsMap.put("id", entity.getId());
			parmsMap.put("departmentCode", entity.getDepartmentCode());
			parmsMap.put("departmentName", entity.getDepartmentName());
			parmsMap.put("type", entity.getType());
			parmsMap.put("isDel", entity.getIsDel());
		}
		return departmentDao.updateDepartment(parmsMap);
	}

}
